package com.gdd.videos.mini_api.common;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;

import javax.servlet.MultipartConfigElement;
import java.io.IOException;

/**
 * @author zhangh     
 * @version V1.0.0
 * @projectName parent
 * @title     IndexSwaggerConfig   
 * @package    com.gdd.videos.mini_api.common  
 * @date   2019/9/11 15:19  
 * @explain 项目启动时默认打开swagger页面
 */
@Configuration
public class IndexSwaggerConfig {

    @Value("${server.port}")
    String projectPort;

    /**
     * 设置项目启动后访问地址
     */
    //@EventListener({ApplicationReadyEvent.class})
    //public void applicationReadyEvent(){
    //    System.out.println("启动完成");
    //    // 启动后访问地址
    //    String url = "http://localhost:"+projectPort+"/swagger-ui.html";
    //    Runtime runtime = Runtime.getRuntime();
    //    try {
    //        runtime.exec("rundll32 url.dll,FileProtocolHandler " + url);
    //    } catch (IOException e) {
    //        e.printStackTrace();
    //    }
    //}

    /**
     * 配置文件上传大小
     */
    @Bean
    public MultipartConfigElement multipartConfigElement(){
        MultipartConfigFactory factory = new MultipartConfigFactory();
        //  单个数据大小 10M
        factory.setMaxFileSize("10240KB");
        /// 总上传数据大小 10M
        factory.setMaxRequestSize("10240KB");
        return factory.createMultipartConfig();
    }

}
